//
//  coins_B1.m
//  K-Music
//
//  Created by CHUN on 16/1/15.
//  Copyright © 2016年 CHUN. All rights reserved.
//

#import "coins_B1.h"
#import "CustomSearch.h"


@interface coins_B1 ()<UITableViewDelegate ,UITableViewDataSource>

@end

@implementation coins_B1

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGB(241, 241, 241);
    self.navigationItem.title = @"我的金币";
  
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"back" highIcon:@"back" target:self action:@selector(back_back)];
    
    [self creatUI];
}
- (void)back_back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -creatUI-
- (void)creatUI
{
    UITableView * conins_B1_TableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    conins_B1_TableView.delegate = self;
    conins_B1_TableView.dataSource =self;
    conins_B1_TableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    conins_B1_TableView.backgroundColor = RGB(241, 241, 241);
    [self.view addSubview:conins_B1_TableView];
    
}


#pragma mark -UITableViewDataSource-

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        return 80;
    }
    if (indexPath.section == 2) {
        return 50;
    }
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellID = @"cellID";
    UITableViewCell * coinsCell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (coinsCell == nil) {
        coinsCell  = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    coinsCell.backgroundColor = [UIColor clearColor];

    coinsCell.selectionStyle = UITableViewCellSelectionStyleNone;

    if (indexPath.section == 0) {
        
        UIImageView * bg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"preson_b"]];
        bg.frame = CGRectMake(0, 0, WIDTH, 100);
        
        [coinsCell.contentView addSubview:bg];
        
        UIImageView * icon = [[UIImageView alloc] init];
        
        NSString * imageurl = [NSString stringWithFormat:@"%@",[FileStorage NSUserDefault_getObjectForKey:user_image]];
        
        if ([imageurl isEqualToString:@"001"]) {
            icon.image=[UIImage imageNamed:@"icon_person"];
        }
        else
        {
            [icon sd_setImageWithURL:[NSURL URLWithString:imageurl]];
        }
        //icon.image = [UIImage imageNamed:@"king_icon1"];
        [coinsCell.contentView addSubview:icon];
        icon.layer.cornerRadius= 25;
        icon.layer.masksToBounds = YES;
    
        
        UILabel * titleName = [[UILabel alloc] init];
        titleName.text = [NSString stringWithFormat:@"%@",[FileStorage NSUserDefault_getObjectForKey:nickName]];
        titleName.font = [UIFont systemFontOfSize:15];
        titleName.textColor = [UIColor whiteColor];
        [coinsCell.contentView addSubview:titleName];
        
        UILabel * coinName = [[UILabel alloc] init];
        coinName.text = @"拥有金币数为";
        coinName.font = [UIFont systemFontOfSize:15];
        coinName.textColor = [UIColor whiteColor];
        [coinsCell.contentView addSubview:coinName];
        
        UILabel * coinsNumber = [[UILabel alloc] init];
        coinsNumber.text = [NSString stringWithFormat:@"%@",[FileStorage NSUserDefault_getObjectForKey:user_goldCoin]];
        coinsNumber.font = [UIFont systemFontOfSize:30];
        coinsNumber.textColor = RGB(234, 149, 67);
        [coinsCell.contentView addSubview:coinsNumber];
        
        UILabel * coinsType = [[UILabel alloc] init];
        coinsType.text = @"金币";
        coinsType.font = [UIFont systemFontOfSize:15];
        coinsType.textColor = [UIColor whiteColor];
        [coinsCell.contentView addSubview:coinsType];
        
        [icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(coinsCell.contentView);
            make.left.equalTo(coinsCell.contentView.mas_left).with.offset(10);
            make.width.and.height.mas_equalTo(@50);
        }];
        
        [titleName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(icon.mas_right).with.offset(10);
            make.top.equalTo(icon.mas_top).with.offset(5);
        }];
        
        [coinName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleName.mas_bottom).with.offset(5);
            make.left.equalTo(icon.mas_right).with.offset(10);
        }];
        
        [coinsNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(coinsType.mas_left).with.offset(-10);
            make.centerY.equalTo(coinsCell.contentView);
        }];
        
        [coinsType mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(coinsCell.contentView.mas_right).with.offset(-10);
            make.centerY.equalTo(coinsCell.contentView);
        }];
        
        
    }
    if (indexPath.section == 1) {
        
        UILabel * title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
        title.text = @"充值数";
        
        CustomSearch * search = [[CustomSearch alloc] init];
        search.backgroundColor = [UIColor whiteColor];
        [search CustomSearchLeftImage:title RightImage:nil ShowString:@"输入需要充值的金币整数" FontSize:15 ClearBtn:YES];
        [coinsCell.contentView addSubview:search];
        
        [search mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(coinsCell.contentView.mas_left);
            make.right.equalTo(coinsCell.contentView.mas_right);
            make.height.mas_equalTo(@50);
            make.centerY.equalTo(coinsCell.contentView);
        }];
    }
    if (indexPath.section == 2) {
        UILabel * payLabel = [[UILabel alloc] init];
        payLabel.font = [UIFont systemFontOfSize:15];
        payLabel.numberOfLines = 0;
        payLabel.text = @"*充值备注,1元可以购买100金币,会员可以享受7折优惠";
        payLabel.textColor = RGB(234, 149, 67);
        [coinsCell.contentView addSubview:payLabel];
        
        [payLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(coinsCell.contentView.mas_left).with.offset(10);
            make.right.equalTo(coinsCell.contentView.mas_right).with.offset(-10);
        }];
    }
    if (indexPath.section == 3) {
        UIButton * payButton = [[UIButton alloc] init];
        [payButton setTitle:@"充值" forState:UIControlStateNormal];
        [payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        payButton.backgroundColor = RGB(234, 149, 67);
        [coinsCell.contentView addSubview:payButton];
        
        [payButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(coinsCell.contentView.mas_left).with.offset(15);
            make.right.equalTo(coinsCell.contentView.mas_right).with.offset(-15);
            make.height.mas_equalTo(@44);
        }];
    }
    return coinsCell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:tableView.indexPathForSelectedRow animated:YES];
}


@end
